package com.zqq.goods.service.repository

import com.zqq.baselibrary.http.RetrofitFactory
import com.zqq.baselibrary.http.rx.BaseResp
import com.zqq.goods.service.api.GoodsApi
import com.zqq.goods.service.bean.GetGoodsDetailReq
import com.zqq.goods.service.bean.GetGoodsListByKeywordReq
import com.zqq.goods.service.bean.GetGoodsListReq
import com.zqq.goods.service.bean.Goods
import rx.Observable
import javax.inject.Inject

/**
 * 商品数据层
 * wc
 * @author zqq on 2019/5/28.
 */
class GoodsRepository @Inject constructor() {


    /**
     * 根据分类搜索商品
     */
    fun getGoodsList(categoryId: Int, pageNo: Int): Observable<BaseResp<MutableList<Goods>?>> {
        return RetrofitFactory.instance
                .create(GoodsApi::class.java)
                .getGoodsList(GetGoodsListReq(categoryId, pageNo))
    }

    /*
       根据关键字搜索商品
    */
    fun getGoodsListByKeyword(keyword: String, pageNo: Int): Observable<BaseResp<MutableList<Goods>?>> {
        return RetrofitFactory.instance
                .create(GoodsApi::class.java)
                .getGoodsListByKeyword(GetGoodsListByKeywordReq(keyword, pageNo))
    }

    /*
        商品详情
     */
    fun getGoodsDetail(goodsId: Int): Observable<BaseResp<Goods>> {
        return RetrofitFactory.instance
                .create(GoodsApi::class.java)
                .getGoodsDetail(GetGoodsDetailReq(goodsId))
    }


}